package com.unionpay.mpds.web.action;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.unionpay.mpds.util.Constants;
import com.unionpay.mpds.util.Trees;
import com.unionpay.mpds.vo.ReturnParams;

public abstract class BaseAction extends ActionSupport {

	protected final Log log = LogFactory.getLog(getClass());
	private static final long serialVersionUID = 4363572172849229047L;
	
	//没有权限
	public static final String NOPERMIT="nopermission";
	//不存在
	public static final String NOTEXIST="not_exist";
	//系统关闭
	public static final String SYSCLOSED="sys_close";
	//未激活
	public static final String UNCHECKED="unchecked";
	//被屏蔽
	public static final String BLACK="black";
	//后台未登录
	public static final String NOLOGIN="no_login";
	public static final String DATA = "data";
	private int pageNum=0;
	private int pageSize = Constants.DEFAULT_PAGE_SIZE;
	public ReturnParams returnParams =  new ReturnParams();
		
	/**
	 * 获取树节点
	 * @param id
	 * @param name
	 * @param open
	 * @param hasSub
	 * @return
	 */
	protected Trees getTreeNode(String id,String name,String open,Boolean hasSub){
		Trees tree=new Trees();
		tree.setId(id);
		tree.setText(name);
		tree.setOpen(open);
		if(hasSub){
			Trees tmp=new Trees();
			tmp.setId("-1");
			tree.getItem().add(tmp);
		}
		return tree;
	}
	
	/**
	 * 
	 * 获得Session
	 */
	public Map<String, Object> getSession() {
		return ActionContext.getContext().getSession();
	}
	
	/**
	 * 
	 * 获得ActionContext
	 */
	public ActionContext getActionContext() {
		return ActionContext.getContext();
	}
	
	/**
	 * 获得HttpServletRequest
	 */
	public HttpServletRequest getHttpServletRequest() {
		return ServletActionContext.getRequest();
	}
	
	/**
	 * 获得HttpServletResponse
	 */
	public HttpServletResponse getHttpServletResponse() {
		return ServletActionContext.getResponse();
	}
	
	public HttpSession getHttpSession() {
		return getHttpServletRequest().getSession();
	}
	
	/**
	 * 获得ServletContext
	 */
	public ServletContext getServletContext() {
		return ServletActionContext.getServletContext();
	}
	/**
	 * 输出字符串
	 * @param message
	 * @throws Exception
	 */
	protected void write(String message)throws Exception{
		getHttpServletResponse().setContentType("text/html");
		getHttpServletResponse().setCharacterEncoding("utf-8");
		getHttpServletResponse().getWriter().write(message);
		getHttpServletResponse().getWriter().flush();
	}
	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public ReturnParams getReturnParams() {
		return returnParams;
	}

	public void setReturnParams(ReturnParams returnParams) {
		this.returnParams = returnParams;
	}
	
}
